using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Text;

namespace Data_Access_Tier
{
	public class HRM_PROCESS_RATEData : DatabaseObjectBase
	{
		public HRM_PROCESS_RATEData()
		{
			Initialize(true);
		}
		public HRM_PROCESS_RATEData(Boolean newConnection)
		{
			Initialize(newConnection);
		}

		public Int32 HRM_PROCESS_RATE_Insert(Guid RateID, String EmployeeCode, DateTime Date, String Violation, Boolean IsRecidivism, Boolean IsDiscipline, Double Minus, Double MyPlus, String MyRate, Double OwnerPlus, String OwnerRate, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.InsertCommand = new SqlCommand("HRM_PROCESS_RATE_Insert");
				_dbadapter.InsertCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.InsertCommand.Connection = _dbconn;
				_trans = _dbconn.BeginTransaction();
				_dbadapter.InsertCommand.Transaction = _trans;
				_dbadapter.InsertCommand.Parameters.Clear();
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Violation", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IsRecidivism", SqlDbType.Bit));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@IsDiscipline", SqlDbType.Bit));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Minus", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@MyPlus", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@MyRate", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OwnerPlus", SqlDbType.Float));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@OwnerRate", SqlDbType.NVarChar, 100));
				_dbadapter.InsertCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.InsertCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.InsertCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.InsertCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.InsertCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ViolationSQL = Violation;
				_dbadapter.InsertCommand.Parameters["@Violation"].Value = ViolationSQL;
				SqlBoolean IsRecidivismSQL = IsRecidivism;
				_dbadapter.InsertCommand.Parameters["@IsRecidivism"].Value = IsRecidivismSQL;
				SqlBoolean IsDisciplineSQL = IsDiscipline;
				_dbadapter.InsertCommand.Parameters["@IsDiscipline"].Value = IsDisciplineSQL;
				SqlDouble MinusSQL = Minus;
				_dbadapter.InsertCommand.Parameters["@Minus"].Value = MinusSQL;
				SqlDouble MyPlusSQL = MyPlus;
				_dbadapter.InsertCommand.Parameters["@MyPlus"].Value = MyPlusSQL;
				SqlString MyRateSQL = MyRate;
				_dbadapter.InsertCommand.Parameters["@MyRate"].Value = MyRateSQL;
				SqlDouble OwnerPlusSQL = OwnerPlus;
				_dbadapter.InsertCommand.Parameters["@OwnerPlus"].Value = OwnerPlusSQL;
				SqlString OwnerRateSQL = OwnerRate;
				_dbadapter.InsertCommand.Parameters["@OwnerRate"].Value = OwnerRateSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.InsertCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.InsertCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATE_Insert: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Insert: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.InsertCommand != null)
					_dbadapter.InsertCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATE_Update(Guid RateID, String EmployeeCode, DateTime Date, String Violation, Boolean IsRecidivism, Boolean IsDiscipline, Double Minus, Double MyPlus, String MyRate, Double OwnerPlus, String OwnerRate, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATE_Update");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Violation", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsRecidivism", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsDiscipline", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Minus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MyPlus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MyRate", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OwnerPlus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OwnerRate", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.UpdateCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ViolationSQL = Violation;
				_dbadapter.UpdateCommand.Parameters["@Violation"].Value = ViolationSQL;
				SqlBoolean IsRecidivismSQL = IsRecidivism;
				_dbadapter.UpdateCommand.Parameters["@IsRecidivism"].Value = IsRecidivismSQL;
				SqlBoolean IsDisciplineSQL = IsDiscipline;
				_dbadapter.UpdateCommand.Parameters["@IsDiscipline"].Value = IsDisciplineSQL;
				SqlDouble MinusSQL = Minus;
				_dbadapter.UpdateCommand.Parameters["@Minus"].Value = MinusSQL;
				SqlDouble MyPlusSQL = MyPlus;
				_dbadapter.UpdateCommand.Parameters["@MyPlus"].Value = MyPlusSQL;
				SqlString MyRateSQL = MyRate;
				_dbadapter.UpdateCommand.Parameters["@MyRate"].Value = MyRateSQL;
				SqlDouble OwnerPlusSQL = OwnerPlus;
				_dbadapter.UpdateCommand.Parameters["@OwnerPlus"].Value = OwnerPlusSQL;
				SqlString OwnerRateSQL = OwnerRate;
				_dbadapter.UpdateCommand.Parameters["@OwnerRate"].Value = OwnerRateSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATE_Update: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Update: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATE_Disable(Guid RateID, ref Boolean Enabled)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATE_Disable");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@enabled", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.UpdateCommand.Parameters["@RateID"].Value = RateIDSQL;
				_dbadapter.UpdateCommand.Parameters["@enabled"].Direction = ParameterDirection.Output;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATE_Disable: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Disable: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATE_Delete(Guid RateID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.DeleteCommand = new SqlCommand("HRM_PROCESS_RATE_Delete");
				_dbadapter.DeleteCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.DeleteCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.DeleteCommand.Transaction = _trans;

				_dbadapter.DeleteCommand.Parameters.Clear();
				_dbadapter.DeleteCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.DeleteCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.DeleteCommand.Parameters["@RateID"].Value = RateIDSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.DeleteCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATE_Delete: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Delete: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.DeleteCommand != null)
					_dbadapter.DeleteCommand.Dispose();
				CloseConnection();
			}
		}
		public Int32 HRM_PROCESS_RATE_Save(Guid RateID, String EmployeeCode, DateTime Date, String Violation, Boolean IsRecidivism, Boolean IsDiscipline, Double Minus, Double MyPlus, String MyRate, Double OwnerPlus, String OwnerRate, String Description)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.UpdateCommand = new SqlCommand("HRM_PROCESS_RATE_Save");
				_dbadapter.UpdateCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.UpdateCommand.Connection = _dbconn;

				_trans = _dbconn.BeginTransaction();
				_dbadapter.UpdateCommand.Transaction = _trans;

				_dbadapter.UpdateCommand.Parameters.Clear();
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@EmployeeCode", SqlDbType.VarChar, 20));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Date", SqlDbType.DateTime));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Violation", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsRecidivism", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@IsDiscipline", SqlDbType.Bit));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Minus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MyPlus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@MyRate", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OwnerPlus", SqlDbType.Float));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@OwnerRate", SqlDbType.NVarChar, 100));
				_dbadapter.UpdateCommand.Parameters.Add(new SqlParameter("@Description", SqlDbType.NVarChar, 255));
				_dbadapter.UpdateCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.UpdateCommand.Parameters["@RateID"].Value = RateIDSQL;
				SqlString EmployeeCodeSQL = EmployeeCode;
				_dbadapter.UpdateCommand.Parameters["@EmployeeCode"].Value = EmployeeCodeSQL;
				SqlDateTime DateSQL = SqlDateTime.Null;
				if (Date > DateTime.MinValue)
				{
					try
					{
						DateSQL = Date;
					}
					catch (Exception eDate)
					{
						String DateMessage = eDate.Message;
						DateSQL = SqlDateTime.Null;
					}
				}
				_dbadapter.UpdateCommand.Parameters["@Date"].Value = DateSQL;
				SqlString ViolationSQL = Violation;
				_dbadapter.UpdateCommand.Parameters["@Violation"].Value = ViolationSQL;
				SqlBoolean IsRecidivismSQL = IsRecidivism;
				_dbadapter.UpdateCommand.Parameters["@IsRecidivism"].Value = IsRecidivismSQL;
				SqlBoolean IsDisciplineSQL = IsDiscipline;
				_dbadapter.UpdateCommand.Parameters["@IsDiscipline"].Value = IsDisciplineSQL;
				SqlDouble MinusSQL = Minus;
				_dbadapter.UpdateCommand.Parameters["@Minus"].Value = MinusSQL;
				SqlDouble MyPlusSQL = MyPlus;
				_dbadapter.UpdateCommand.Parameters["@MyPlus"].Value = MyPlusSQL;
				SqlString MyRateSQL = MyRate;
				_dbadapter.UpdateCommand.Parameters["@MyRate"].Value = MyRateSQL;
				SqlDouble OwnerPlusSQL = OwnerPlus;
				_dbadapter.UpdateCommand.Parameters["@OwnerPlus"].Value = OwnerPlusSQL;
				SqlString OwnerRateSQL = OwnerRate;
				_dbadapter.UpdateCommand.Parameters["@OwnerRate"].Value = OwnerRateSQL;
				SqlString DescriptionSQL = Description;
				_dbadapter.UpdateCommand.Parameters["@Description"].Value = DescriptionSQL;
				Int32 returnvalue = Convert.ToInt32(_dbadapter.UpdateCommand.ExecuteScalar());

				_trans.Commit();
				return returnvalue;
			}
			catch (SqlException e)
			{
				try
				{
					_trans.Rollback();
				}
				catch (SqlException ex)
				{
					throw new Exception("SQL Rollback Error: HRM_PROCESS_RATE_Save: " + ex.Message, ex);
				}
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Save: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.UpdateCommand != null)
					_dbadapter.UpdateCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_RATE_GetList()
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_RATE_GetList");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Prepare();
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_RATE_GetList: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
		public DataSet HRM_PROCESS_RATE_Get(Guid RateID)
		{
			try
			{
				if (_dbconn.State != ConnectionState.Open)
					_dbconn.Open();
				_dbadapter.SelectCommand = new SqlCommand("HRM_PROCESS_RATE_Get");
				_dbadapter.SelectCommand.CommandType = CommandType.StoredProcedure;
				_dbadapter.SelectCommand.Connection = _dbconn;
				_dbadapter.SelectCommand.Parameters.Clear();
				_dbadapter.SelectCommand.Parameters.Add(new SqlParameter("@RateID", SqlDbType.UniqueIdentifier));
				_dbadapter.SelectCommand.Prepare();
				SqlGuid RateIDSQL = RateID;
				_dbadapter.SelectCommand.Parameters["@RateID"].Value = RateIDSQL;
				_dbadapter.Fill(_data);

				return _data;
			}
			catch (SqlException e)
			{
				throw new Exception("SQL Error: HRM_PROCESS_RATE_Get: " + e.Message, e);
			}
			finally
			{
				if (_dbadapter.SelectCommand != null)
					_dbadapter.SelectCommand.Dispose();
				CloseConnection();
			}
		}
	}
}
